package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.ReservationCountVo;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 参观预约接口
 */
@Slf4j
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "参观预约接口")
public class CustomerReservationController extends BaseController {
    @Autowired
    CustomerReservationService customerReservationService;

    /**
     * 查询取消预约数量
     */
    @ApiOperation("查询取消预约数量")
    @GetMapping("/cancelled-count")
    public ResponseResult<Integer> getCancelledCount() {
        log.info("查询取消预约数量");
        Integer cancelledCount = customerReservationService.getCancelledCount();
        return success(cancelledCount);
    }

    /**
     * 查询每个时间段剩余预约次数
     * @param time
     * @return
     */
    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public ResponseResult<List<ReservationCountVo>> getCountByTime(Long time) {
        log.info("查询每个时间段剩余预约次数:{}",time);
        List<ReservationCountVo> timeList = customerReservationService.getCountByTime(time);
        return success(timeList);
    }

    /**
     * 新增预约
     * @param reservationDto
     * @return
     */
    @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult save(@RequestBody ReservationDto reservationDto) {
        log.info("新增预约: {}",reservationDto);
        customerReservationService.save(reservationDto);
        return success();
    }

    /**
     * 分页查询预约
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public ResponseResult<ReservationVo> list(Integer pageNum,Integer pageSize,Integer status) {
        log.info("分页查询预约: {},{},{}",pageNum,pageNum,status);
        PageResponse<ReservationVo> pageResponse = customerReservationService.list(pageNum,pageSize,status);
        return success(pageResponse);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id) {
        log.info("取消预约: {}",id);
        customerReservationService.cancel(id);
        return success();
    }
}
